<%@ page import="stockService.imgService" %>
<%@ page import="stockService.loadData" %>
<%@ page import="stockService.searchResult" %>
<%@ page import="java.text.DecimalFormat" %>
<%--
  Created by IntelliJ IDEA.
  User: chen
  Date: 10/04/2018
  Time: 11:52 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/bootstrap.min.css">

    <!-- Optional JavaScript -->
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="js/refresh.js"></script>

    <title>股票查询</title>
</head>
<body>
<form class="search-form" role="search">
    <div class="form-group">
        <input type="text" name="search" class="form-control search" placeholder="请输入股票代码" style="display: inline"/>
        <button type="submit" class="btn btn-default search-btn">搜索</button>
        <div class="search-res">
            <%
                String searchnow = request.getParameter("search");
                if (searchnow != null && !searchnow.equals("")) {
                    searchResult.addResult(searchnow);
                    loadData.setStock(searchnow);
                }
                String[] searchres = searchResult.getResult();
                for (int i = 0; i < 5; i++) {
                    if (searchres[i] != null && searchres[i] != "") {
            %><a href="http://localhost:8080/?search=<%=searchres[i]%>"
                 class=" btn btn-default search-res-list"><%=searchres[i]%>
        </a><%
                }
            }
            int count = loadData.count;
        %>
        </div>
    </div>
</form>
<div style="margin-top: 22px;">
    <ul class="nav nav-tabs">
        <li class="tabs-space">
            <p class="tabs-space"></p>
        </li>
        <li>
            <a name="hour" href="javascript:void(0)" onclick="imgrefresh(0)">分时线</a>
        </li>
        <li>
            <a name="daily" href="javascript:void(0)" onclick="imgrefresh(1)">日K线</a>
        </li>
        <li>
            <a name="weekly" href="javascript:void(0)" onclick="imgrefresh(2)">周K线</a>
        </li>
        <li>
            <a name="monthly" href="javascript:void(0)" onclick="imgrefresh(3)">月K线</a>
        </li>
        <li class="pull-right">
            <div style="max-width: 700px; margin-top: -25px">
                <div class="info pull-right">
                    <h5 class="price">总成交金额:</h5>
                    <h5 class="price" name="price" id="tprice"><%=loadData.stocks[loadData.cur].price%>
                    </h5>
                </div>
                <div class="info pull-right">
                    <h5 class="price">总成交股票:</h5>
                    <h5 class="price" name="quantity" id="tquan"><%=loadData.stocks[loadData.cur].quan%>
                    </h5>
                </div>
                <div class="info pull-right">
                    <h5 class="price">今日最低价:</h5>
                    <h5 class="price" name="lowest" id="tlow"><%=loadData.stocks[loadData.cur].lowest%>
                    </h5>
                </div>
                <div class="info pull-right">
                    <h5 class="price">今日最高价:</h5>
                    <h5 class="price" name="highest" id="thigh"><%=loadData.stocks[loadData.cur].highest%>
                    </h5>
                </div>
                <div class="info pull-right">
                    <h5 class="price">昨日收盘价:</h5>
                    <h5 class="price" name="lastday" id="tlast"><%=loadData.stocks[loadData.cur].last%>
                    </h5>
                </div>
                <div class="info pull-right">
                    <h5 class="price">今日开盘价:</h5>
                    <h5 class="price" name="today" id="ttoday"><%=loadData.stocks[loadData.cur].today%>
                    </h5>
                </div>
                <div class="info pull-right">
                    <h5 class="price">当前价格:</h5>
                    <h5 class="price" name="current" id="tcur"><%=loadData.stocks[loadData.cur].current%>
                    </h5>
                </div>
                <div class="info pull-right">
                    <h5 class="price">涨跌:</h5>
                    <h5 class="price" name="current" id="tperc"><%=new DecimalFormat("0.00%").format(loadData.stocks[loadData.cur].perc)%>
                    </h5>
                    <%
                        if(loadData.stocks[loadData.cur].perc < 0){
                    %><script>document.getElementById("tperc").style.color = '#00FF00'</script><%
                        }
                        else{
                %><script>document.getElementById("tperc").style.color = '#FF0000'</script><%
                        }
                    %>
                </div>
            </div>
        </li>

    </ul>
</div>
<div class="middle">
    <div class="img pull-left">
    <span id="sp">
      <%
          if (loadData.stocks[loadData.cur].name.equals("Error Stock")) {
      %><img class="img-self" src="img/error.jpg"><%
    } else {
    %><img class="img-self" src="<%=imgService.getImg(-1)%>"> <%
        }
    %>
    </span>
    </div>
    <div class="side pull-right">
        <ul class="list-group">
            <li class="list-group-item" style="border: 0px;">
                <button class="btn btn-default btn-sm dropdown-toggle list-btn" type="button" data-toggle="dropdown"
                        aria-haspopup="true" aria-expanded="false">显示股票列表 <span class="caret"></span></button>
                <ul class="dropdown-menu" style="margin-left: -260px; margin-top: -10px; min-width: 480px;">
                    <%
                        if (count > 0) {
                            for (int i = 0; i < count; i++) {
                    %>
                    <li><a href="javascript:void(0)" class="btn-list-item"
                           onclick="currefresh(<%=i%>);">
                        <%
                            if(loadData.stocks[i].perc < 0){
                        %><span id="bperc<%=i%>" style="color: #00FF00;"><%=new DecimalFormat("#.##%").format(loadData.stocks[i].perc)%></span><%
                        }
                        else{
                        %><span id="bperc<%=i%>" style="color: #FF0000;"><%=new DecimalFormat("#.##%").format(loadData.stocks[i].perc)%></span><%
                            }
                        %>
                        <span id="bcode<%=i%>"><%=loadData.stocks[i].code%></span>
                        <span id="bname<%=i%>"><%=loadData.stocks[i].name%></span>
                        <span id="bcur<%=i%>">当前：<%=loadData.stocks[i].current%></span>
                        <span id="btoday<%=i%>">今开：<%=loadData.stocks[i].today%></span>
                        <span id="blast<%=i%>">昨收：<%=loadData.stocks[i].last%></span>
                        <span id="bhigh<%=i%>">最高：<%=loadData.stocks[i].highest%></span>
                        <span id="blow<%=i%>">最低：<%=loadData.stocks[i].lowest%></span>
                    </a></li>
                    <%
                        }
                    } else {
                    %>
                    <li><a class="btn-list-item">没有选择股票</a></li>
                    <%
                        }
                    %>
                </ul>
            </li>
        </ul>
        <div class="transaction pull-left">
            <ul class="list-group price-list">
                <li class="list-group-item">
                    <h5 class="price">竞买价:</h5>
                    <h5 class="price" id="lbuy"><%=loadData.stocks[loadData.cur].bprice[0]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">买一申请:</h5>
                    <h5 class="price" id="lbquan1"><%=loadData.stocks[loadData.cur].bquan[0]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">买一价格:</h5>
                    <h5 class="price" id="lbprice1"><%=loadData.stocks[loadData.cur].bprice[0]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">买二申请:</h5>
                    <h5 class="price" id="lbquan2"><%=loadData.stocks[loadData.cur].bquan[1]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">买二价格:</h5>
                    <h5 class="price" id="lbprice2"><%=loadData.stocks[loadData.cur].bprice[1]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">买三申请:</h5>
                    <h5 class="price" id="lbquan3"><%=loadData.stocks[loadData.cur].bquan[2]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">买三价格:</h5>
                    <h5 class="price" id="lbprice3"><%=loadData.stocks[loadData.cur].bprice[2]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">买四申请:</h5>
                    <h5 class="price" id="lbquan4"><%=loadData.stocks[loadData.cur].bquan[3]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">买四价格:</h5>
                    <h5 class="price" id="lbprice4"><%=loadData.stocks[loadData.cur].bprice[3]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">买五申请:</h5>
                    <h5 class="price" id="lbquan5"><%=loadData.stocks[loadData.cur].bquan[4]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">买五价格:</h5>
                    <h5 class="price" id="lbprice5"><%=loadData.stocks[loadData.cur].bprice[4]%>
                    </h5>
                </li>
            </ul>
        </div>
        <div class="transaction pull-right">
            <ul class="list-group price-list">
                <li class="list-group-item">
                    <h5 class="price">竞卖价:</h5>
                    <h5 class="price" id="lsell"><%=loadData.stocks[loadData.cur].sprice[0]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">卖一申请:</h5>
                    <h5 class="price" id="lsquan1"><%=loadData.stocks[loadData.cur].squan[0]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">卖一价格:</h5>
                    <h5 class="price" id="lsprice1"><%=loadData.stocks[loadData.cur].sprice[0]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">卖二申请:</h5>
                    <h5 class="price" id="lsquan2"><%=loadData.stocks[loadData.cur].squan[1]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">卖二价格:</h5>
                    <h5 class="price" id="lsprice2"><%=loadData.stocks[loadData.cur].sprice[1]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">卖三申请:</h5>
                    <h5 class="price" id="lsquan3"><%=loadData.stocks[loadData.cur].squan[2]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">卖三价格:</h5>
                    <h5 class="price" id="lsprice3"><%=loadData.stocks[loadData.cur].sprice[2]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">卖四申请:</h5>
                    <h5 class="price" id="lsquan4"><%=loadData.stocks[loadData.cur].squan[3]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">卖四价格:</h5>
                    <h5 class="price" id="lsprice4"><%=loadData.stocks[loadData.cur].sprice[3]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">卖五申请:</h5>
                    <h5 class="price" id="lsquan5"><%=loadData.stocks[loadData.cur].squan[4]%>
                    </h5>
                </li>
                <li class="list-group-item">
                    <h5 class="price">卖五价格:</h5>
                    <h5 class="price" id="lsprice5"><%=loadData.stocks[loadData.cur].sprice[4]%>
                    </h5>
                </li>
            </ul>
        </div>
    </div>
</div>
<div class="refresh-div pull-right">
    <h6 id="refresh"></h6>
</div>
</body>
</html>